package engine.logic
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.utils.Dictionary;
	
	import newx.com.ResManager;
	import newx.utils.MemoryOptimise;

	public class McPool
	{	
		private static	var _mcList	:Dictionary	= new Dictionary( true );
		
		public static function borrowRes( url : String ):*
		{
//			trace("borrowRes---------------------------------->>   "  + url);
			if( url == "" || url == null ) return null;
			
			var mc : Sprite;
			
			if( null == _mcList[url] )
			{
				_mcList[url] = [];
			}
			
			if( 0 == _mcList[url].length )
			{
				mc	=	ResManager.newResClass( url ) as MovieClip;
			}else
			{
				mc	=	_mcList[url].shift();
			}
			if( mc is MovieClip )
			{
				mc["url"] = url;
			}
			if( mc is DisplayObject )
			{
				mc.mouseChildren = mc.mouseEnabled = false;
			}
			
			return mc;
		}
		
		public static function returnRes( url : String, mc : * ):void
		{
//			trace("returnRes---------------------------------->>   "  + url);
			if( mc is MovieClip )
			{
				MemoryOptimise.stopMovie( mc );
			}
			
			if( null == _mcList[url] )
			{
				_mcList[url] = [];
			}
			
			if( null != mc )
			{
				_mcList[url].push( mc );

			}
		}
	}
}